package com.wswy.wyjk.model

import com.wswy.wyjk.model.dto.RecordDto

data class RecordData(private val recordDto: RecordDto,
                 private val practiceType: PracticeType
                      ) {


    val questionId = recordDto.questionId

    val chapterId = recordDto.chapterId

    /**
     * 顺序练习
     */
    var orderAnswer = recordDto.orderAnswer
    set(value) {
        field = value
        recordDto.orderAnswer=value
    }

    /**
     * 随机练习
     */
    var randomAnswer = recordDto.randomAnswer
    set(value) {
        field = value
        recordDto.randomAnswer = value
    }

    /**
     * 章节练习
     */
    var chapterAnswer = recordDto.chapterAnswer
    set(value) {
        field = value
        recordDto.chapterAnswer = value
    }

    /**
     * 错题
     */
    var erroAnswer = recordDto.erroAnswer
        set(value) {
            field = value
            recordDto.erroAnswer = value
        }

    /**
     * 难题练习
     */
    var difficultAnswer = recordDto.difficultAnswer
    set(value) {
        field = value
        recordDto.difficultAnswer = value
    }

    var undoneAnswer = recordDto.undoneAnswer
    set(value) {
        field = value
        recordDto.undoneAnswer = value
    }

    var examAnswer = 0

    val dtoRef = recordDto

    /**
     * 是否有答题
     */
    fun hasAnswer():Boolean{
          //判断answer列是否有数据
        return when(practiceType.type){
            PracticeType.TYPE_ORDER -> orderAnswer != 0
            PracticeType.TYPE_RANDOM -> randomAnswer != 0
            PracticeType.TYPE_CHAPTER -> chapterAnswer != 0
            PracticeType.TYPE_ERROR -> erroAnswer != 0
            PracticeType.TYPE_DIFFICULTY -> difficultAnswer != 0
            PracticeType.TYPE_UNDONE -> undoneAnswer != 0
            PracticeType.TYPE_EXAM -> examAnswer != 0
            else -> false
        }
    }


    /**
     * 获取类型填写的答案
     */
    fun getTypeAnswer():Int{
        return when(practiceType.type){
            PracticeType.TYPE_ORDER -> orderAnswer
            PracticeType.TYPE_RANDOM -> randomAnswer
            PracticeType.TYPE_CHAPTER -> chapterAnswer
            PracticeType.TYPE_ERROR -> erroAnswer
            PracticeType.TYPE_DIFFICULTY -> difficultAnswer
            PracticeType.TYPE_UNDONE -> undoneAnswer
            PracticeType.TYPE_EXAM -> examAnswer
            else -> 0
        }
    }

    override fun toString(): String {
        return "RecordData( questionId=$questionId, chapterId=$chapterId, randomAnswer=$randomAnswer, orderAnswer=$orderAnswer, dtoRef=$dtoRef)"
    }


}